package com.xqm.springcloud.controller;
import com.xqm.springcloud.pojo.UserInfo;
import com.xqm.springcloud.mapper.UserInfoMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ShiMing
 * @version 1.0
 * @name UserController
 * @description TODO
 * @date 2020/8/20
 */

@RestController
public class UserController {

    @Autowired
    UserInfoMapper userInfoMapper;

    @GetMapping("/userinfos")
    public List<UserInfo> userinfos(String message) {
        System.out.println("UserController.userinfos  lineNum:29, param:{message = [" + message + "]} info:");
        return userInfoMapper.selectAll();
    }


    @PostMapping("/userinfos")
    public List<UserInfo> userinfo(@RequestBody String message) {
        System.out.println("message");

        return userInfoMapper.selectAll();
    }

    @Autowired
    EurekaDiscoveryClient client;

    /**
     * 获取注册的微服务的信息
     * @return
     */
    @GetMapping("/discovery")
    public Object discovery() {
        List<?> servers = client.getServices();
        System.out.println(servers);
        List<?> list = client.getInstances("PROVIDER-8001");
        for (Object o : list) {
            System.out.println(o);
        }
        return client.getInstances("PROVIDER-8001");
    }
}
